/** constructor

 @param duration integer seconds
 @param <optional> function to run while waiting.

 */
function Pause(duration, busy)
{
   this.duration = duration * 1000;
   this.busywork = null;
   // function to call while waiting.
   this.runner = 0;

   if (arguments.length == 2)
   {
      this.busywork = busy;
   }

   this.pause(this.duration);

}
// Pause class

/** pause method

 @param duration: integer in seconds

 */
Pause.prototype.pause = function(duration)
{
   if ((duration == null) || (duration < 0))
   {
      return;
   }

   var later = (new Date()).getTime() + duration;

   while (true)
   {
      if ((new Date()).getTime() > later)
      {
         break;
      }

      this.runner++;

      if (this.busywork != null)
      {
         this.busywork(this.runner);
      }

   }
   // while

} // pause method

